package Easy;

public class LC0643 {
    public double findMaxAverage(int[] nums, int k) {
        int maxSum = 0, length = nums.length;
        for (int i = 0; i < k; i++) maxSum += nums[i];
        int sum = maxSum;
        for (int i = 1; i <= length - 1 - k + 1; i++) {
            sum -= nums[i - 1];
            sum += nums[i + k - 1];
            if (sum > maxSum) maxSum = sum;
        }

        return maxSum * 1.0 / k;
    }
}
